package com.hq.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hq.service.HouseService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class HouseController {

    @Resource
    private HouseService houseService;

    @RequestMapping("/list.do")
    public String  list(Model model, @RequestParam(value="cpage",defaultValue = "1") Integer cpage,
                        String mohu1, Integer mohu2){

        Map map=new HashMap<>();
        map.put("mohu1",mohu1);
        map.put("mohu2",mohu2);
        System.out.println(map);
        PageHelper.startPage(cpage,3);
        List<Map<String, Object>> list = houseService.list(map);
        PageInfo<Map<String, Object>> pi = new PageInfo<>(list);
        model.addAttribute("pi",pi);
        model.addAttribute("map",map);
        return "list";

    }
    @RequestMapping("/del.do")
    @ResponseBody
    public Object del(Integer id){
        int i=houseService.del(id);
        return i;
    }

    @RequestMapping("/cz.do")
    @ResponseBody
    public Object cz(Integer id){
        int i=houseService.cz(id);
        return i;
    }
}
